package org.chengn.level_easy.context1696;

import java.util.Stack;

/**
 * @Title: Context2696
 * @Author ChengN
 * @Package org.chengn.level_easy.context1696
 * @Date 2024/1/10 0:09
 * @description: 删除子串后的字符串最小长度
 */
public class Context2696 {
    public int minLength(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); ++i) {
            char c = s.charAt(i);
            if (stack.empty() || (c != 'B' && c != 'D')) {
                stack.push(c);
                continue;
            }
            if (c == 'B' && stack.peek() == 'A' || c == 'D' && stack.peek() == 'C')
                stack.pop();
            else stack.push(c);
        }
        return stack.size();
    }
}
